package com.demo.controller;


import com.demo.entity.Message;
import com.demo.response.Result;
import com.demo.service.IMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * 消息记录表 前端控制器
 * @author zm
 * @since 2020-11-24
 */
@RestController
@RequestMapping("/message")
@Api(tags = "消息管理类")
public class MessageController {
    @Autowired
    IMessageService messageService;

    @ApiOperation("更新消息")
    @PostMapping("/updateMessageService")
    public Result updateMessageService(@RequestBody Message message, BindingResult result){
        if (result.hasErrors()){
            return Result.error(result.getFieldError().getDefaultMessage());
        }
        return messageService.updateMessageService(message);
    }

    @ApiOperation("删除消息")
    @GetMapping("/deleteMessageService")
    public Result deleteMessageService(@RequestParam(name = "messageId",required = true)Integer messageId,
                                       @RequestParam(name = "deletedUserId",required = true)Integer deletedUserId){
        return messageService.deleteMessageService(messageId, deletedUserId);
    }

    @ApiOperation(value = "消息列表", tags = {"消息管理类", "v20210507更新", "v20210507更新"})
    @GetMapping("/messageServiceList")
    public Result messageServiceList(@RequestParam(name = "pageNumber",required = false,defaultValue = "1")Integer pageNumber,
                                     @RequestParam(name = "pageSize",required = false,defaultValue = "20")Integer pageSize,
                                     @RequestParam(name = "status",required = false)Integer status){
        return messageService.messageServiceListV2(pageNumber, pageSize, status);
    }

}
